package cn.tedu.file;

import java.io.*;

/*本类用于练习字节输出流OutputStream*/
public class TestOut {
    public static void main(String[] args) {
        //method1();//用来测试普通字节输出流
        method2();//用来测试高效字节输出流
    }
    //用来测试高效字节输出流BufferedOutputStream
    private static void method2() {
        BufferedOutputStream out = null;
        try {
//            out = new BufferedOutputStream(new FileOutputStream("D:\\ready\\1.txt",true));
//            out = new BufferedOutputStream(new FileOutputStream("D:\\ready\\1.txt"));
            out = new BufferedOutputStream(new FileOutputStream(new File("D:\\ready\\1.txt"),true));
//            out = new BufferedOutputStream(new FileOutputStream(new File("D:\\ready\\1.txt")));


            out.write(98);
            out.write(15445);
            out.write(54564);
            out.write(49536);
            out.write(94154);
            out.write(91143);
            out.write(94849);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    //用来测试普通字节输出流FileOutputStream
    private static void method1() {
        FileOutputStream out = null;
        try {
//            out =new FileOutputStream(new File("D:\\ready\\1.txt"));//覆盖输出
//            out =new FileOutputStream("D:\\ready\\1.txt");//覆盖输出
            out =new FileOutputStream(new File("D:\\ready\\1.txt"),true);//追加输出
            out =new FileOutputStream("D:\\ready\\1.txt",true);//追加输出
           //使用流对象--进行数据的输出操作
            out.write(97);
            out.write(98);
            out.write(99);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {//如果想要代码一定会被执行到就需要把数据
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
